﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;

using ProductsWebApi.Models;


namespace ProductsWebApi.Controllers
{
    public class ProductsController : ApiController
    {
        Product[] products = new Product[]
        {
            new Product{Id=1,Name="Tomato-Soup",Category="Groceries",Price=1},
            new Product{Id=2,Name="Yo-Yo",Category="Toys",Price=3.75M},
            new Product{Id=3,Name="Hammer",Category="Hardware",Price=16.99M}

        };

        public IEnumerable<Product> GetAllProducts()
        {
            return products;
        }

        public IHttpActionResult GetProduct(int Id)
        {
            var product = products.FirstOrDefault((p) => p.Id == Id);
            if (product == null)
            {
                return NotFound();
            }

            return Ok(product);
        }

    }
}
